<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        /* 
            需求：将数组中的元素每个值都 x 2
         */

         const array1 = [1,2,3,4,5,6];

         
         //方式一
        //  let count = 0;
        //  for(let item of array1){
        //      array1[count] = item*2
        //      count++
        //  }
        //  console.log(array1)
        

        //方式二
/*        function add(num){
            return num*2
        }
         const result = array1.map(add)
        console.log(result) */


        //方式三
        // const s1 = array1.map(obj => obj*2)
        // console.log(s1)


        /* 
            需求：将每个人的age都+1
         */
         const names = [
            { name: '李四',age: 23 },
            { name: '赵六',age: 24 },
            { name: '张三',age: 32 }
        ];
        const result = names.map(obj => obj.age+1+","+obj.name)
        console.log(result)

        /* 
            匿名函数：obj => obj.age+1
            function (obj){
                return obj.age+1
            }
         */
    </script>
</head>
<body>
    
</body>
</html> 